import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Index from '../components/Index.vue'
import Singer from '../components/Singer.vue'
import NewAlbum from '../components/NewAlbum.vue'
import Top from '../components/Top.vue'
import PlayList from '../components/PlayList.vue'
import SingerInfo from '../components/SingerInfo.vue'
import AlbumInfo from '../components/AlbumInfo.vue'
import PlayListInfo from '../components/PlayListInfo.vue'
import MV from '../components/MV.vue'
import MVInfo from '../components/MVInfo.vue'

import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  { 
    path: '/home', component: Home, redirect: '/index',
    children: [
      { path: '/index', component:  Index },
      { path: '/singer', component:  Singer },
      { path: '/new/album', component: NewAlbum },
      { path: '/top', component: Top },
      { path: '/playlist', component: PlayList },
      { path: '/singer/info/:id', component: SingerInfo },
      { path: '/album/info/:id', component: AlbumInfo },
      { path: '/playlist/info/:id', component: PlayListInfo },
      { path: '/mv', component: MV },
      { path: '/mv/info/:id', component: MVInfo },
    ]
  },
]

const router = new VueRouter({
  routes
})

const VueRouterPush = VueRouter.prototype.push 
VueRouter.prototype.push = function push (to) {
    return VueRouterPush.call(this, to).catch(err => err)
}

router.beforeEach((to, from, next) => {
  Nprogress.start();
  next();
})

router.afterEach(() => {
  Nprogress.done();
})

export default router
